﻿using HECore.SerilogWebApi.Filters;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Serilog;
using Serilog.Context;
using Serilog.Extensions.Hosting;

namespace HECore.SerilogWebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class HomeController : ControllerBase
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IDiagnosticContext _diagnosticContext;

        public HomeController(ILogger<HomeController> logger, IDiagnosticContext diagnosticContext)
        {
            _logger = logger;
            _diagnosticContext= diagnosticContext;
        }

        [HttpGet("LogInformation")]
        [RequestAuditLog]
        public string LogInformation()
        {
            return "ok";
        }

        [HttpGet("LogError")]
        [RequestAuditLog]
        public string LogError()
        {
            int a = 10;
            int b = 0;
            int c = a / b;
            return "ok";
        }

        [HttpPost("LogRequest")]
        [RequestAuditLog]
        public List<string> LogRequest([FromBody] List<string> input)
        {
            for (int i = 0; i < 10; i++)
            {
                input.Add(Guid.NewGuid().ToString());
            }
            return input;
        }
    }
}
